package br.com.salao.session;

import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

import br.com.salao.ejb.dao.EnderecoDao;
import br.com.salao.ejb.dao.impl.EnderecoDaoImpl;
import br.com.salao.entity.Endereco;

@Stateless
@Remote(EnderecoBase.class)
public class EnderecoBean implements EnderecoBase{

	/**
	 * @author Dri
	 */
	private static final long serialVersionUID = 1L;

	@PersistenceContext(unitName = "SalaoBeleza")
	private EntityManager em;

	public EnderecoBean(){
		//em = JpaUtil.getEntityManager();	
	}

	@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)
	public Endereco buscarEnderecoPorLogradouro(Endereco endereco){
		EnderecoDao dao = new EnderecoDaoImpl(em);
		return dao.buscarEnderecoPorLogradouro(endereco);
	}
	
	@TransactionAttribute
	public Endereco inserir(Endereco endereco){
		EnderecoDao dao = new EnderecoDaoImpl(em);
		return dao.inserir(endereco);
	}	
	
	@TransactionAttribute
	public Endereco update(Endereco endereco){
		EnderecoDao dao = new EnderecoDaoImpl(em);
		return dao.update(endereco);
	}	
	
	@TransactionAttribute
	public void deletar(int id){
		EnderecoDao dao = new EnderecoDaoImpl(em);
		dao.deletar(id);
	}
}
